import { get, post } from '@/utils/request'

export default {
	// 提交商品
	async submitGoods(data) {
		try {
			const res = await post('/api/goods/submit', data)
			return res.data
		} catch (err) {
			console.error('提交商品失败:', err)
			throw err
		}
	},
	async bannerListData() {
		const res = await post('/api/goods/bannerListData', {})
		return res.data
	},
	async goodsList(params = {}) {
		// 解构分页参数，提供默认值
		const { page = 1, pageSize = 10 } = params;
		const res = await post('/api/goods/goodsList', { page, pageSize, ...params })
		return res.data
	},
	async goodsDetail(id) {
		const res = await post('/api/goods/goodsDetail', { id: id })
		return res.data
	},
	// 获取常见问题数据
	async commonQuestions(goodsId) {
		const res = await post('/api/goods/commonQuestions', { goods_id: goodsId })
		return res.data
	},
	// 获取商品问答数据
	async goodsQuestions(goodsId) {
		const res = await post('/api/goods/goodsQuestions', { goods_id: goodsId })
		return res.data
	},
	//获取商品评论
	async goodsComments(goodsId) {
		const res = await post('/api/goods/comments', { goods_id: goodsId })
		return res.data
	},
	// 根据分类生成规格参数
	async generateCategorySpecs(category) {
		const res = await post('/api/goods/generateCategorySpecs', { goods_id: goodsId })
		return res.data
	}
}
